<template>
	<view>
		<view class="status-box">
			<view class="status">
				{{data.statusName}}
			</view>
			<view class="tip">
				{{data.statusDetails}}
			</view>
		</view>
		<view class="address-box row deliver" v-if="data.status == 3 || data.status == 4 || data.status == 5">
			<image src="../../static/img/sh.png" mode="" class="dw"></image>
			<view class="info">
				<view class="">
					<text class="name">送货类型：{{data.deliveryType == 0 ? '快递配送':'公司自送'}}</text>
				</view>
				<view class="address" v-if="data.deliveryTime != ''">
					送货日期：{{data.deliveryTime}}
				</view>
				<view class="address" v-if="data.deliveryCompany != ''">
					快递公司：{{data.deliveryCompany}}
				</view>
				<view class="address" v-if="data.logisticsNo != ''">
					运送单号：{{data.logisticsNo}}
				</view>
			</view>
		</view>
		<view class="address-box row">
			<image src="../../static/img/dw.png" mode="" class="dw"></image>
			<view class="info">
				<view class="">
					<text class="name">{{data.name}}</text>
					<text class="tel">{{data.mobile}}</text>
				</view>
				<view class="address">
					{{data.address}}
				</view>
			</view>
		</view>
		<view class="info-box">
			<view class="good-case">
				<view class="good-item row" v-for="(item,index) in data.headGoodsList" :key="index">
					<view class="left row">
						<image :src="item.titleImg" mode="aspectFill" class="goods-img"></image>
						<view class="content">
							<view class="title">
								{{item.goodsName}}
							</view>
							<view class="color">
								规格：{{item.sku}}
							</view>
						</view>
					</view>
					<view class="right">
						<view class="day-rent">
							出售金额:<text>￥</text>{{item.price}}元
							<view class="amount">
								x{{item.quantity}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="info-bar row">
				<text class="title">商品总金额 </text>
				<text>￥{{data.sumMoney}}</text>
			</view>
			<view class="info-bar row">
				<text class="title">运费</text>
				<text>￥{{data.expressFee}}</text>
			</view>
			<view class="money-bar row">
				<text class="intro">付款总金额</text>
				<text class="money">￥{{data.payMoney}}</text>
			</view>
		</view>
		<view class="order-info">
			<view class="title">
				订单信息
			</view>
			<view class="value">订单来源：{{data.orderSource==1 ? '微信下单': '手工录入'}}</view>
			<view class="value">订单类型：{{data.orderType ==2 ? '租赁订单':'出售订单'}} </view>
			<view class="value">订单编号：{{data.orderSn}}</view>
		</view>
		<view class="footer row" v-if="data.status == 0">
			<view class="pay-btn" @click="pay">
				支付
			</view>
			<view class="cancel-btn" @click="cancel">
				取消
			</view>
		</view>
		<view class="footer row" v-if="data.status != 0 && data.status != 6">
			<view class="pay-btn" v-if="data.status == 4" @click="toConfirm">
				确认完成
			</view>
			<view class="cancel-btn" v-if="data.status == 4">
				联系客服
			</view>
			<view class="pay-btn" v-if="data.status != 4">
				联系客服
			</view>
		</view>
	</view>
</template>

<script>
	import comm from '../../static/data/commFunc.js'
	import cfg from '../../static/data/config.js'
	var r = cfg.router;
	export default {
		data() {
			return {
				orderSn: "",
				data: {},
				// list: [1, 2],
				status: 0
			};
		},
		onLoad(e) {
			this.orderSn = e.orderSn
		},
		onShow() {
			comm.request("POST", "/public/customerMobile", {}, (res, data) => {
				console.log("客服电话", res)
				if (res.data.ret_code == 200) {
					this.customerMobile = data.mobile
				} 
			})
			this.getData()
		},
		onPullDownRefresh() {
			this.getData()
			uni.stopPullDownRefresh()
		},
		methods: {
			pay() {
				var that = this;
				uni.showModal({
					title: '温馨提示',
					content: '您确定支付吗',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							let data = {
								orderSn: that.orderSn,
								payWay: 0
							}
							comm.request("POST", "/app/order/getPay", data, (res, data) => {
								console.log("微信支付", res)
								if (res.data.ret_code == 200) {
									uni.requestPayment({
										provider: 'wxpay',
										timeStamp: data.timeStamp,
										nonceStr: data.nonceStr,
										package: "prepay_id=" + data.prepayId,
										signType: "HMAC-SHA256",
										paySign: data.sign,
										success(res) {
											comm.showToast("支付成功")
											that.getData()
										},
										fail(res) {
											console.log("支付失败");
											comm.showToast("支付失败", "none")
										},
									});
								} else {
									comm.showToast(res.data.ret_msg, "none")
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			//取消订单
			cancel() {
				var that = this;
				uni.showModal({
					title: '温馨提示',
					content: '您确定取消订单吗',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							let data = {
								orderSn: that.orderSn,
							}
							comm.request("POST", "/app/order/cancelOrder", data, (res, data) => {
								console.log("取消订单", res)
								if (res.data.ret_code == 200) {
									comm.showToast("取消成功")
									that.getData()
								} else {
									comm.showToast(res.data.ret_msg, "none")
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			getData() {
				let data = {
					orderSn: this.orderSn
				}
				comm.request("POST", "/app/order/getOrder", data, (res, data) => {
					console.log("订单详情", res)
					if (res.data.ret_code == 200) {
						this.data = data
					} else {
						comm.showToast(res.data.ret_msg, "none")
					}
				})
			},
			toConfirm() {
				let data = {
					orderSn: this.orderSn
				}
				comm.request("POST", "/app/order/confirm", data, (res, data) => {
					console.log("确认订单", res)
					if (res.data.ret_code == 200) {
						this.getData()
						comm.showToast("确认完成")
					} else {
						comm.showToast(res.data.ret_msg, "none")
					}
				})
			},
			contact(){
				var that = this;
				uni.makePhoneCall({
					// 手机号
					phoneNumber: that.customerMobile,
				
					// 成功回调
					success: (res) => {
						console.log('调用成功!')
					},
					// 失败回调
					fail: (res) => {
						console.log('调用失败!')
					}
				});
			}
		}
	}
</script>

<style lang="less">
	.status-box {
		padding: 30rpx;
		background: #D93011;

		.status {
			font-size: 38rpx;
			font-weight: bold;
			color: rgba(255, 255, 255, 1);
			margin-bottom: 20rpx;
		}

		.tip {
			font-size: 24rpx;
			color: rgba(255, 255, 255, 1);
		}
	}

	.address-box {
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx;
		padding: 30rpx;
		justify-content: space-between;

		.dw {
			width: 64rpx;
			height: 64rpx;
			margin-right: 30rpx;
		}

		.info {
			flex: 1;

			.name {
				font-size: 30rpx;
				font-weight: bold;
				color: rgba(25, 17, 11, 1);
				margin-right: 30rpx;
			}

			.tel,
			.address {
				font-size: 24rpx;
				color: rgba(153, 153, 153, 1);
				word-break: break-word;
			}

			.address {
				margin-top: 10rpx;
			}
		}
	}

	.deliver {
		align-items: flex-start;
	}

	.info-box {
		background: rgba(255, 255, 255, 1);
		border-radius: 20rpx;
		padding: 30rpx;
		margin: 30rpx 0;
		border-bottom: 14rpx solid #F9F9F8;
		border-top: 14rpx solid #F9F9F8;

		.good-case {
			border-bottom: 1rpx solid #EEEEEE;
			margin-bottom: 30rpx;

			.good-item {
				margin-bottom: 30rpx;
				justify-content: space-between;
				align-items: flex-start;

				.left {
					flex: 1;
					align-items: flex-start;

					.goods-img {
						width: 120rpx;
						height: 120rpx;
						border-radius: 10rpx;
						background: #F9F9F8;
						margin-right: 30rpx;
					}

					.content {
						flex: 1;

						.title {
							font-size: 24rpx;
							color: rgba(51, 51, 51, 1);
						}

						.color,
						.size {
							font-size: 20rpx;
							color: rgba(153, 153, 153, 1);
							margin-top: 10rpx;
						}
					}
				}

				.right {
					text-align: right;

					.day-rent {
						font-size: 24rpx;
						color: rgba(51, 51, 51, 1);

						text {
							font-size: 26rpx;
						}
					}

					.amount {
						font-size: 24rpx;
						color: rgba(153, 153, 153, 1);
					}
				}
			}
		}

		.info-bar {
			justify-content: space-between;
			font-size: 22rpx;
			color: #999999;
			margin: 10rpx 0;

			.title {
				width: 130rpx;
			}
		}

		.money-bar {
			justify-content: space-between;
			font-size: 26rpx;
			margin-top: 10rpx;
			color: #333333;
		}
	}

	.order-info {
		margin: 0 30rpx;
		padding-bottom: 120rpx;

		.title {
			color: #333333;
			font-size: 28rpx;
		}

		.value {
			color: #999999;
			font-size: 22rpx;
			margin-top: 20rpx;
		}
	}

	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		background: #FFFFFF;
		box-shadow: 0rpx 6rpx 10rpx 0rpx rgba(0, 0, 0, 0.04);
		justify-content: flex-end;
		padding: 30rpx;
		box-sizing: border-box;
		z-index: 99;

		.pay-btn,
		.cancel-btn {
			// width:167rpx;
			// height: 60rpx;
			// line-height: 60rpx;
			padding: 10rpx 30rpx;
			text-align: center;
			border-radius: 30rpx;
			font-size: 26rpx;
		}

		.pay-btn {
			background: rgba(217, 48, 17, 1);
			color: #FFFFFF;
			margin-right: 30rpx;
		}

		.cancel-btn {
			border: 1rpx solid rgba(217, 48, 17, 1);
			color: #D93011;
		}
	}
</style>
